/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mycompany.delivery.transfers;

import com.mycompany.delivery.dto.DeliveryDTO;
import com.mycompany.delivery.entities.Courier;
import com.mycompany.delivery.entities.Delivery;
import com.mycompany.delivery.entities.Employee;

/**
 *
 * @author mhunek
 */
public class DeliveryT {

    public static DeliveryDTO EntityToDTO(Delivery delivery) {
        DeliveryDTO deliveryDTO = new DeliveryDTO();
        if (delivery.getCourier() != null) {
            deliveryDTO.setCourier(delivery.getCourier().getId());
        } else {
            deliveryDTO.setCourier(0l);
        }
        if (delivery.getEmployee() != null) {
            deliveryDTO.setEmployee(delivery.getEmployee().getId());
        } else {
            deliveryDTO.setEmployee(0l);
        }
        deliveryDTO.setDeliveryDate(delivery.getDeliveryDate());
        deliveryDTO.setId(delivery.getId());
        deliveryDTO.setNotes(delivery.getNotes());
        deliveryDTO.setPaid(delivery.isPaid());
        deliveryDTO.setPrice(delivery.getPrice());
        deliveryDTO.setSendingDate(delivery.getSendingDate());
        deliveryDTO.setSender(ContactT.entityToDTO(delivery.getSender()));
        deliveryDTO.setReceiver(ContactT.entityToDTO(delivery.getReceiver()));
        deliveryDTO.setState(EnumT.StateToDTOState(delivery.getState()));

        return deliveryDTO;
    }

    public static Delivery dTOtoEntity(DeliveryDTO deliveryDTO) {
        Delivery delivery = new Delivery();
        delivery.setDeliveryDate(deliveryDTO.getDeliveryDate());
        delivery.setId(deliveryDTO.getId());
        delivery.setNotes(deliveryDTO.getNotes());
        delivery.setPaid(deliveryDTO.isPaid());
        delivery.setPrice(deliveryDTO.getPrice());
        delivery.setSendingDate(deliveryDTO.getSendingDate());
        delivery.setSender(ContactT.dTOtoEntity(deliveryDTO.getSender()));
        delivery.setReceiver(ContactT.dTOtoEntity(deliveryDTO.getReceiver()));
        delivery.setState(EnumT.DTOStateToState(deliveryDTO.getState()));

        return delivery;
    }

    public static Delivery dTOtoEntity(DeliveryDTO deliveryDTO, Employee empl, Courier cour) {
        Delivery delivery = new Delivery();
        delivery.setCourier(cour);
        delivery.setEmployee(empl);
        delivery.setDeliveryDate(deliveryDTO.getDeliveryDate());
        delivery.setId(deliveryDTO.getId());
        delivery.setNotes(deliveryDTO.getNotes());
        delivery.setPaid(deliveryDTO.isPaid());
        delivery.setPrice(deliveryDTO.getPrice());
        delivery.setSendingDate(deliveryDTO.getSendingDate());
        delivery.setSender(ContactT.dTOtoEntity(deliveryDTO.getSender()));
        delivery.setReceiver(ContactT.dTOtoEntity(deliveryDTO.getReceiver()));
        delivery.setState(EnumT.DTOStateToState(deliveryDTO.getState()));

        return delivery;
    }

    public static Delivery dTOtoEntity(DeliveryDTO deliveryDTO, Employee empl) {
        Delivery delivery = new Delivery();
        delivery.setEmployee(empl);
        delivery.setDeliveryDate(deliveryDTO.getDeliveryDate());
        delivery.setId(deliveryDTO.getId());
        delivery.setNotes(deliveryDTO.getNotes());
        delivery.setPaid(deliveryDTO.isPaid());
        delivery.setPrice(deliveryDTO.getPrice());
        delivery.setSendingDate(deliveryDTO.getSendingDate());
        delivery.setSender(ContactT.dTOtoEntity(deliveryDTO.getSender()));
        delivery.setReceiver(ContactT.dTOtoEntity(deliveryDTO.getReceiver()));
        delivery.setState(EnumT.DTOStateToState(deliveryDTO.getState()));

        return delivery;
    }

    public static Delivery dTOtoEntity(DeliveryDTO deliveryDTO, Courier cour) {
        Delivery delivery = new Delivery();
        delivery.setCourier(cour);
        delivery.setDeliveryDate(deliveryDTO.getDeliveryDate());
        delivery.setId(deliveryDTO.getId());
        delivery.setNotes(deliveryDTO.getNotes());
        delivery.setPaid(deliveryDTO.isPaid());
        delivery.setPrice(deliveryDTO.getPrice());
        delivery.setSendingDate(deliveryDTO.getSendingDate());
        delivery.setSender(ContactT.dTOtoEntity(deliveryDTO.getSender()));
        delivery.setReceiver(ContactT.dTOtoEntity(deliveryDTO.getReceiver()));
        delivery.setState(EnumT.DTOStateToState(deliveryDTO.getState()));

        return delivery;
    }
}
